package com.shushan.manager;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.shushan.base.NavigationLoseActivity;
import com.shushan.manager.adapter.TimeManagerAdapter;
import com.shushan.shushanbao.BabyApplication;
import com.shushan.shushanbao.R;
import com.shushan.util.UmengEventUtil;

/**
 * @ClassName: TimeManagerActivity
 * @Desciption: 时间管理
 * @author: yichaohua
 * @date: 2018-07-18
 */
public class TimeManagerActivity extends NavigationLoseActivity implements View.OnClickListener {

    private static final String TAG = "TimeManagerActivity";

    private Button addButton;
    private ListView listView;
    private TimeManagerAdapter timeManagerAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle("时间管理");

        setContentView(R.layout.time_mg_activity);

        initView();

        getTime();

        UmengEventUtil.onEvent(BabyApplication.getInstance(),"time_manager_page_id");
    }

    private void initView() {
        listView = findViewById(R.id.time_mg_lv);
        addButton = findViewById(R.id.time_my_add_btn);
        addButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.time_my_add_btn:
                startActivityForResult(UseTimeAddActivity.class);
                break;
            default:
                break;
        }
    }

    private void getTime() {
        timeManagerAdapter = new TimeManagerAdapter(this);
        listView.setAdapter(timeManagerAdapter);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == 100){
            timeManagerAdapter.notifyDataChanged();
        }
    }
}
